import {defineStore} from "pinia";
import {ref} from "vue";

export const useTeacherStores = defineStore('teacherStore',() => {
    const sum_stu = ref(0) // 学生总数
    const sum_class = ref(0) // 授课班级总数
    const sum_lectures = ref(0) // 授课课程总数

    const tea_classes = ref([{'classId': '1', 'collegeId': 1, 'majorId': '080902', 'name': '23软件工程一班','teacherId': '辅导员'}])
    const tea_lecture = ref([{'classId': 1, 'courseId':1, 'semester': 2, 'type': '专业必修课'}])
    const tea_courses = ref([{'courseId': '课程号', 'credit': '学分', 'name': '名字'}])
    const scores = ref([

    ])
    function teacherInit(data){
        console.log("更新教师初始化信息")
        sum_stu.value = data.sumStudents
        sum_class.value = data.sumClasses
        sum_lectures.value = data.sumLecturers

        tea_classes.value = data.teaClasses
        tea_lecture.value = data.teaLectures
        tea_courses.value = data.teaCourses
    }

    function updateStudentScore(stuId, courseId, newScore) {
        const scoreRecord = scores.value.find(score =>
            score.stuId === stuId && score.courseId === courseId
        );
        if (scoreRecord) {
            scoreRecord.tempScore = newScore;
            scoreRecord.status = '1'
            return true;
        }
        // 未找到记录
        return false;
    }

    function resetTeaData(){
        sum_stu.value = 0
        sum_class.value = 0
        sum_lectures.value = 0
        tea_lecture.value = []
        tea_courses.value = []
        tea_classes.value = []
        scores.value = []
    }

    return { sum_stu, sum_class, sum_lectures, tea_classes, tea_lecture, tea_courses, scores, resetTeaData, teacherInit, updateStudentScore }
})